package com.tianzeculture.stagebao.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.network.util.ToastUtil;

/**
 * Created by Administrator on 2018/5/24 0024.
 */

public class TagDialog {


    private Dialog dialog;
    private OnSelectClickListener onSelectClickListener;

    public TagDialog(Context context) {
        init(context);
    }

    private void init(final Context context) {
        dialog = new Dialog(context, R.style.DialogPushUpInAnimStyle);
        dialog.setContentView(R.layout.dialog_tag);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);

        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        window.setAttributes(layoutParams);

        final EditText edtTag = window.findViewById(R.id.edtTag);
        Button btnCancel = window.findViewById(R.id.btnCancel);
        Button btnSure = window.findViewById(R.id.btnSure);

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSelectClickListener.onOk(edtTag.getText().toString().trim());
                dismiss();
            }
        });
    }


    /**
     *
     */
    public void show() {
        dialog.show();
    }

    /**
     *
     */
    public void dismiss() {
        dialog.dismiss();
        if (onSelectClickListener != null) {
            onSelectClickListener.onCancel();
        }
    }

    public OnSelectClickListener getOnSelectClickListener() {
        return onSelectClickListener;
    }

    public void setOnSelectClickListener(OnSelectClickListener onSelectClickListener) {
        this.onSelectClickListener = onSelectClickListener;
    }


    public interface OnSelectClickListener {
        void onOk(String tagString);

        void onCancel();
    }
}
